package thread.simple;

public class YieldThread extends Thread {

private static int threadCount = 0;
	
	private int countDown = 50;
	
	public YieldThread() {
		super("" + ++threadCount); // Store the thread name
		start();
	}
	
	@Override
	public void run() {
		while(true) {
			System.out.println(this);
			if(--countDown == 0)
				return;
			yield();
		}
	}
	
	public String toString() {
		return "#" + getName() + ": " + countDown;
	}
	
	public static void main(String[] args) {
		for(int i = 0; i < 5; i++) {
			new YieldThread();
		}
	}
}
